/**var P_{$smarty.foreach.img.iteration}=new Product(); P_{$smarty.foreach.img.iteration}.show('{$img.original_pic}'); **/

function Product ()
 {  
 this.img_url='';
 this.i=1;
 this.uploadbutton;
 _this=this;
 $(' input[name="pro_url[]"]').each(function(index, element) {
    _this.i++;
	
        });
	
  Product.prototype.create_html=function(url){
	
    var html=' <div class="left-table">产品图片：</div>';
	html+='<div class="right-table"><input type="text" name="pro_url[]" value="'+url+'"  id="url'+_this.i+'"/></div>';
	html+='<div class="msg-s">';
	html+='<a href="javascript:;" class="localUpload f_l" onclick="$(\'input[name=thumb'+_this.i+']\').click()">本地上传</a>';
	html+='<a href="javascript::" class="add-pic" onclick="addNewPic()">添加新图片</a>';
	html+='<input id="uploadButton'+_this.i+'" type="button" value="submit" />';
	html+='</div>';
		
	html+='<div class="height_10"></div>';
	$(html).appendTo("#pro");
	  }
    
    
	Product.prototype.show= function(url){
		 if(typeof(url)=='undefined')
		 {
			url=''; 
		 }
		_this.create_html(url);
		var i=_this.i;
		var uploadbutton;
		KindEditor.ready(function(K) {
		
		
     window.editor = K.create('#pro-view');
	
	uploadbutton = K.uploadbutton({
		 
					button : K('#uploadButton'+i)[0],
					fieldName : 'thumb'+i,
					url : 'index.php?g=admin&m=pro&a=file&num='+i,
					afterUpload : function(data) {
						
						if (data.error === 0) {
							var url = K.formatUrl(data.url, 'absolute');
							
							K('#url'+i).val(url);
						} else {
							alert(data.message);
						}
					},
					afterError : function(str) {
						alert('自定义错误信息: ' + str);
					}
				});
	
	
	 uploadbutton.fileBox.change(function(e) {
					uploadbutton.submit();
					
				});
				
				
					
					
		 
		 
		});   
			
	
		}
 }